<?php
    // array for JSON response
    $response = array();
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
    // connecting to db
    $db = new DB_CONNECT();
    $stt = 1;
    // get all products from products table
    if(isset($_GET['user_id_zing'])){
        if(isset($_GET['state'])){
            if(isset($_GET['sttComment'])){
                    $result = mysql_query("SELECT place.place_id, place.place_name, place.address, place.url_avatar, place.name_avatar, comment.detail_comment, comment.time_comment, comment.comment_id FROM comment, place WHERE comment.user_id_zing =".$_GET['user_id_zing']
                . " and comment.place_id = place.place_id ORDER BY comment.time_comment DESC LIMIT  ".$_GET['sttComment']." , 5") or die(mysql_error());
                }
        }else{
            $result = mysql_query("SELECT place.place_id, place.place_name, place.address, place.url_avatar, place.name_avatar, comment.detail_comment, comment.time_comment, comment.comment_id FROM comment, place WHERE comment.user_id_zing =".$_GET['user_id_zing']
                . " and comment.place_id = place.place_id ORDER BY comment.time_comment DESC LIMIT 5") or die(mysql_error());
        }
               
        if (mysql_num_rows($result) > 0) {
                $response["comment"] = array();
                while ($row = mysql_fetch_array($result)) {
                        $comment = array(); 
						$comment['comment_id'] = $row['comment_id'];
                        $comment['place_id'] = $row['place_id'];
                        $comment['place_name'] = $row['place_name'];
                        $comment['address'] = $row['address'];
                        $comment['time_comment'] = $row['time_comment'];
                        $comment['detail_comment'] = $row['detail_comment'];
                        $comment['url_avatar'] = $row['url_avatar'];
						$comment['name_avatar'] = $row['name_avatar'];
                        $comment['stt'] = $stt;
                        $stt++;
                        // push single product into final response array
                        array_push($response['comment'],$comment);
                }
                // success
            $response["success"] = 1;
                echo json_encode($response);
        }
        else{
            $response["comment"] = "No comemnt";
            $response["success"] = 1;
                echo json_encode($response);
        }
    }else{
		$response["subcomment"] = "Error _GET";
        $response["success"] = 0;
        echo json_encode($response);
	}
?>

